package org.lagou.edu.logSdk.thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author 咖啡杯里的茶
 * @date 2022/8/7
 */
public class ThreadPoolUtil {

	private static int corePoolSize = 8;
	private static int maximumPoolSize = 16;
	private static long keepAliveTime = 2;
	private static BlockingDeque<Runnable> blockingDeque = new LinkedBlockingDeque<>(200);

	private static ThreadPoolExecutor threadPoolExecutor;

	static {
		threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MINUTES, blockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
	}

	public static void execute(Runnable runnable) {
			threadPoolExecutor.execute(runnable);
	}
}
